//- 先去这个pug文件中找
extends ../commons/commons.pug

block append pageStyle
	link(href="${relativePath}/static/css/shopping/shopIndex.css" rel="stylesheet" type="text/css")
	link(href="${relativePath}/static/css/personCenter/securityCenter.css" rel="stylesheet" type="text/css")

block content
	//- 新建订单
	div.newOrderContent
		h3.orderTitle
			| 安全中心
			span -修改支付密码
		div.setBox.pswBox
			div.row
				label.fl &nbsp;&nbsp;&nbsp;手机号：
				input.txt.fl.phoneNum(type="text" readonly)
			div.row
				label.fl &nbsp;&nbsp;&nbsp;验证码：
				div.codeM.fl
					input.inpTxt.phoneCode.fl(type="text" name="phoneCode")
					input.inpTxt.passCode(type="button" value="获取验证码")
			div.row
				label.fl 支付密码：
				input.txt.fl.pswOne(type="password" placeholder="请输入")
			div.row
				label.fl 确认密码：
				input.txt.fl.pswTwo(type="password" placeholder="请输入")
			div.row.btnBox
				a.btn.save(href="javascript:;") 保存
				a.btn.cancle(href="javascript:;") 取消


block append pageScript
	script(src="${relativePath}/static/js/jquery.validate.min.js")
	script(src="${relativePath}/static/js/messages_zh.js")
	script(type="text/javascript" src="${relativePath}/static/js/card.js")

	script.
		$(function() {			
			//- 发送验证码
			var countdown=60;
			function settime(obj) {
			    if (countdown == 0) {
			        obj.removeAttribute("disabled");    
			        obj.value="获取验证码";
			        countdown = 60;
			        return;
			    } else {
			        obj.setAttribute("disabled", true);
			        obj.value="重新发送(" + countdown + ")";
			        countdown--;
			    }
			setTimeout(function() {
			    settime(obj) }
			    ,1000)
			}

			//- 点击发送验证码
			$(".passCode").click(function(){
				var phoneNum = $(".phoneNum").val();
				//console.log(phoneNum);
				var _this = this;
				if(phoneNum == ""){
					layer.msg("请输入手机号!");
					return false;
				}else{
					$.post(shopIp+"/Utils/sendCaptcha",{
						phone:$(".phoneNum").val(),
					},function(data){
						//console.log(data);
						if(data.status == "200"){
							settime(_this);
							setTimeout(function() {
								layer.msg(data.msg);
							},1000);
						}else{
							layer.msg(data.msg);
						}
					})
				}
			})

			//- 点击保存
			$.post(shopIp+"/user/info",{
				userToken:token
			},function(data) {
				console.log(data);
				$(".phoneNum").val(data.data.phone)
			})
			$(".save").click(function() {
				if($(".phoneCode").val() == "") {
					layer.msg("请输入验证码");
				} else if($(".pswOne").val() == ""){
					layer.msg("请输入支付密码");
				} else if($(".pswTwo").val() == ""){
					layer.msg("请确认密码");
				} else{
					$.post(shopIp+"/user/setPayPassword",{
						userToken:token,
						phone_sms:$(".phoneCode").val(),
						pay_password:$(".pswOne").val(),
						repay_password:$(".pswTwo").val()
					},function(data){
						if(data.status == "200") {
							layer.msg(data.msg);
							setTimeout(function() {
								window.location.href="securityCenter.html";
							},1500)
						}else {
							layer.msg(data.msg);
						}
					})
				}
			})
			
			//- 点击取消
			$(".cancle").click(function() {
				window.location.href="securityCenter.html";
			})
			
		})
		
		